<template>
  <div
    class="modal fade"
    tabindex="-1"
    role="dialog"
    aria-hidden="true"
    :id="id"
  >
    <div class="modal-dialog modal-dialog-centered">
      <div class="modal-content">
        <div class="modal-header">
          <h4 class="modal-title">
            <span v-if="carrier === ''">新建</span>
            <span v-else>修改</span>
          </h4>
          <button
            type="button"
            class="btn-close"
            data-bs-dismiss="modal"
            aria-label="Close"
          ></button>
        </div>
        <div class="modal-body">
          <form
            id="frmCustomerServiceGroup"
            role="form"
            class="form-horizontal"
          >
            <div class="row">
              <label class="control-label col-4 text-end"> 航司代码 </label>
              <div class="col-8">
                <input
                  type="text"
                  class="form-control"
                  v-model.trim="carrier"
                />
                <span class="text-muted small">仅一个航司代码</span>
              </div>
            </div>
            <div class="row">
              <label class="control-label col-4 text-end"> 舱位 </label>
              <div class="col-8">
                <input
                  type="text"
                  class="form-control"
                  v-model.trim="subclass"
                />
                <span class="text-muted small"
                  >多个舱位使用空格，逗号或者斜线隔开，最大30个字符</span
                >
              </div>
            </div>
            <div class="row">
              <label class="control-label col-4 text-end">
                机票出票服务费
              </label>
              <div class="col-8">
                <input
                  type="text"
                  class="form-control"
                  v-model.number="flightTicketingFee"
                />
                <span class="text-muted small">按每人每段收取</span>
              </div>
            </div>
            <div class="row">
              <label class="control-label col-4 text-end">
                机票退票服务费
              </label>
              <div class="col-8">
                <input
                  type="text"
                  class="form-control"
                  v-model.number="flightRefundFee"
                />
                <span class="text-muted small">按每人每段收取</span>
              </div>
            </div>
            <div class="row">
              <label class="control-label col-4 text-end">
                机票改签服务费
              </label>
              <div class="col-8">
                <input
                  type="text"
                  class="form-control"
                  v-model.number="flightChangeFee"
                />
                <span class="text-muted small">按每人每段收取</span>
              </div>
            </div>
          </form>
        </div>
        <div class="modal-footer">
          <button
            type="button"
            class="btn btn-secondary me-2"
            data-bs-dismiss="modal"
          >
            关闭
          </button>
          <button type="button" class="btn btn-primary" @click.stop="ok()">
            确定
          </button>
        </div>
      </div>
    </div>
  </div>
</template>


<script>
import $ from "jquery";

export default {
  props: {
    nullable: {
      type: Boolean,
      default: true,
    },
    id: {
      type: String,
      default: "customerServiceTemplateModal",
    },
    departments: {
      type: Array,
    },
  },
  data() {
    return {
      resolve: "",
      reject: "",
      promise: "",

      carrier: "",
      subclass: "",
      flightTicketingFee: 0,
      flightRefundFee: 0,
      flightChangeFee: 0,

      myModal: null,
    };
  },
  methods: {
    ok: function () {
      this.hideModal();

      const params = {
        carrier: this.carrier,
        subclass: this.subclass,
        flightTicketingFee: this.flightTicketingFee,
        flightRefundFee: this.flightRefundFee,
        flightChangeFee: this.flightChangeFee,
      };

      this.resolve(params);
    },
    modal: function (v) {
      this.carrier = v.carrier;
      this.subclass = v.subclass;
      this.flightTicketingFee = v.flightTicketingFee;
      this.flightRefundFee = v.flightTicketingFee;
      this.flightChangeFee = v.flightChangeFee;

      this.showModal();

      this.promise = new Promise((resolve, reject) => {
        this.resolve = resolve;
        this.reject = reject;
      });
      return this.promise;
    },
    showModal: function () {
      this.getMyModal().show();
    },
    hideModal: function () {
      this.getMyModal().hide();
    },
    getMyModal: function () {
      if (this.myModal === null) {
        let myModalEl = $(this.$el).get(0);
        this.myModal = new bootstrap.Modal(myModalEl, {
          keyboard: true,
        });
      }

      return this.myModal;
    },
  },
};
</script>
